/**
 * Created by dio on 2017/2/21 0021.
 */
import React from "react";
import {ScrollView, View} from "react-native";
import chjStyle from "../../../CustomStyle";
import ModuleCommonHeader from "../../module/ModuleCommonHeader";
import Util from "../../Util";
import WarrantyInfo from "./WarrantyInfo";
import SingleSelectionTextItem from "../common/SingleSelectionTextItem";
import SwitchTextItem from "../common/SwitchTextItem";
import NextButton from "../common/NextButton";
import {ActionConst, Actions} from "react-native-router-flux";

export default class WarrantyRoadeTest extends React.Component {
    // 构造函数，可执行初始化操作
    constructor(props) {
        super(props);
        // 在ES6，在构造函数里初始化state
        this.state = {};
        if (!Util.selectCar.warrantyroadetest) {
            Util.selectCar.warrantyroadetest = [
                {value: "正常", name: "发动机运转、加速检查"},
                {value: "正常", name: "制动系统工作是否正常有效、制动不跑偏"},
                {value: "正常", name: "车辆启动前踩下制动踏板，保持5秒钟，踏板无向下移动现象"},
                {value: "正常", name: "行驶过程中车辆底盘部位检查"},
                {value: "正常", name: "行驶过程中车辆转向是否平顺，方向机回转检查"},
                {value: "正常", name: "ABS工况检查"},
                {value: "正常", name: "行驶跑偏检查"},
                {value: "正常", name: "变速箱工作检查"},
                {value: "正常", name: "从P挡换至D挡行驶过程中有无顿挫感、冲击感（AT）"},
                {value: "正常", name: "从1挡到R挡挡位是否松旷、闯挡"},
                {value: "正常", name: "换挡或挂挡时挡位是否平顺或异响"},
                {value: "正常", name: "行驶过程中离合器是否有打滑现象"},
                {value: "正常", name: "风扇工作检查"}
            ];
        }
    }

    // 组件被加载时
    componentDidMount() {

    }

    // 组件即将被卸载时
    componentWillUnmount() {
    }

    // 组件被渲染时
    render() {
        return (
            <View style={chjStyle.mainContainer}>
                <ModuleCommonHeader title='路试检查(05)' leftText='返回' clickedRight={this.clickedNew.bind(this)}
                                    rightText='保存'/>
                <ScrollView
                    style={chjStyle.mainList}>
                    {
                        Util.selectCar.warrantyroadetest.map((item, i) => this.renderItem(item, i))
                    }
                </ScrollView>
                <NextButton onClickedListener={() => this.clickedNew()}/>
            </View>
        );
    }

    renderItem(item, i) {
        switch (i) {
            case 7:
                return (
                    <SingleSelectionTextItem object={item} optionArray={[{name: "正常"}, {name: "异常"}, {name: "异响"}]}/>);
            default:
                return (<SwitchTextItem object={item} onValue='正常' offValue='异常'/>);
        }
    }

    clickedNew() {
        Util.saveData('cars', Util.selectCar);
        Actions.WarrantyInfo(
            {
                type: ActionConst.PUSH_OR_POP,
                name: 'WarrantyInfo',
                component: WarrantyInfo,
            }
        );
    }
}